package com.waiter.moximoxi.dialog;

import android.app.Dialog;
import android.content.Context;
import android.view.Gravity;
import android.view.View;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.waiter.moximoxi.R;
import com.waiter.moximoxi.bean.UserConponBean;

import java.util.ArrayList;
import java.util.List;

import cn.yhong.aframework.adapter.ZmAdapter;
import cn.yhong.aframework.adapter.ZmHolder;
import cn.yhong.aframework.dialog.BaseDialog;
import cn.yhong.aframework.listener.OnCallbackListener;

/**
 * Created by 17639 on 2020/10/15.
 */

public class CouponInfoDialog extends BaseDialog implements View.OnClickListener {

    private ImageView dialog_sending_dis;
    private ListView sending_listview;
    private TextView total_count_tv;

    private List<UserConponBean> userConponBeans;
    private CouponInfoAdapter couponInfoAdapter;

    public CouponInfoDialog(Context context, OnCallbackListener onCallbackListener) {
        super(context, onCallbackListener);
    }

    @Override
    public Dialog initDialog(Context context) {
        View view = View.inflate(context, R.layout.dialog_coupon_info, null);
        dialog_sending_dis = view.findViewById(R.id.dialog_sending_dis);
        sending_listview = view.findViewById(R.id.sending_listview);
        total_count_tv = view.findViewById(R.id.total_count_tv);

        dialog_sending_dis.setOnClickListener(this);

        userConponBeans = new ArrayList<>();
        couponInfoAdapter = new CouponInfoAdapter(context, userConponBeans);
        sending_listview.setAdapter(couponInfoAdapter);

        return initMatchWrapDialog(view, context, Gravity.CENTER, android.R.style.Animation_InputMethod);
    }

    public void showCouponInfoDialog(List<UserConponBean> userConponBean) {
        userConponBeans.clear();
        userConponBeans.addAll(userConponBean);
        couponInfoAdapter.notifyDataSetChanged();

        total_count_tv.setText("共" + userConponBean.size() + "张，优惠" + userConponBean.get(0).coupon_fee + "元");
        showDialog();
    }


    class CouponInfoAdapter extends ZmAdapter<UserConponBean> {

        public CouponInfoAdapter(Context mContext, List<UserConponBean> itemList) {
            super(mContext, itemList);
        }

        @Override
        public void init(ZmHolder zmHolder, final UserConponBean userConponBean, final int position) {
            TextView food_name = zmHolder.getView(R.id.food_name);
            TextView food_pirce = zmHolder.getView(R.id.food_pirce);
            TextView coupon_cancle = zmHolder.getView(R.id.coupon_cancle);

            food_name.getPaint().setFakeBoldText(true);
            coupon_cancle.getPaint().setFakeBoldText(true);

            food_name.setText(userConponBean.title);
            food_pirce.setText("¥:" + userConponBean.minus_money);

            coupon_cancle.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    onCallbackListener.onCallback(0, position, userConponBean);
                    dismissDialog();
                }
            });
        }

        @Override
        public int setLayout() {
            return R.layout.item_dialog_coupon_info;
        }
    }


    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.dialog_sending_dis:
                break;
        }
        dismissDialog();
    }
}
